package o;

import android.content.Context;
import androidx.annotation.NonNull;
import com.huawei.appgallery.assistantdock.base.service.base.dispatch.GameServiceDispatchFactory;
import com.huawei.appgallery.assistantdock.base.service.base.dispatch.GameServiceDispatcher;
import com.huawei.gamebox.plugin.gameservice.service.RequestInfo;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class fah {
    private static fah ॱ;
    private Map<String, GameServiceDispatcher> ˊ = new HashMap();
    private String ˏ;

    public static synchronized fah ॱ() {
        fah o_fah;
        synchronized (fah.class) {
            if (ॱ == null) {
                ॱ = new fah();
            }
            o_fah = ॱ;
        }
        return o_fah;
    }

    public synchronized void ˏ(Context context, @NonNull RequestInfo requestInfo, fad o_fad) {
        GameServiceDispatcher gameServiceDispatcher = null;
        String ॱ = requestInfo.ॱ();
        String ˎ = ˎ(requestInfo);
        if (!(ˎ == null || ˎ.equals(this.ˏ))) {
            ˋ();
        }
        if (this.ˊ.containsKey(ॱ)) {
            gameServiceDispatcher = (GameServiceDispatcher) this.ˊ.get(ॱ);
        }
        if (gameServiceDispatcher == null) {
            gameServiceDispatcher = GameServiceDispatchFactory.INSTANCE.createDispatcher(ॱ);
            this.ˊ.put(ॱ, gameServiceDispatcher);
        }
        if (gameServiceDispatcher != null) {
            gameServiceDispatcher.dispatch(context, requestInfo, o_fad);
        }
        this.ˏ = ˎ;
    }

    public synchronized void ˏ(@NonNull RequestInfo requestInfo) {
        if (requestInfo != null) {
            GameServiceDispatcher gameServiceDispatcher = null;
            String ॱ = requestInfo.ॱ();
            String ˎ = ˎ(requestInfo);
            if (Logger.ˎ()) {
                Logger.ˏ("BuoyDispatchManager", "continueProcess:" + ˎ + "," + this.ˏ);
            }
            if (!(ˎ == null || ˎ.equals(this.ˏ))) {
                ˋ();
            }
            if (this.ˊ.containsKey(ॱ)) {
                gameServiceDispatcher = (GameServiceDispatcher) this.ˊ.get(ॱ);
            }
            if (gameServiceDispatcher != null) {
                gameServiceDispatcher.onContinue();
            }
            this.ˏ = ˎ;
        }
    }

    private void ˋ() {
        if (Logger.ˎ()) {
            Logger.ˏ("BuoyDispatchManager", "destroy BuoyDispatchManager");
        }
        for (Entry entry : this.ˊ.entrySet()) {
            if (!(entry == null || entry.getValue() == null)) {
                ((GameServiceDispatcher) entry.getValue()).destroy();
            }
        }
        this.ˊ.clear();
    }

    public synchronized void ˎ() {
        for (Entry entry : this.ˊ.entrySet()) {
            if (!(entry == null || entry.getValue() == null)) {
                ((GameServiceDispatcher) entry.getValue()).unbind();
            }
        }
    }

    public synchronized void ˏ() {
        ˋ();
    }

    private synchronized String ˎ(@NonNull RequestInfo requestInfo) {
        String ˎ;
        ˎ = requestInfo.ˎ();
        if (dof.ॱ(ˎ)) {
            ˎ = requestInfo.ॱॱ();
        }
        return ˎ;
    }
}
